package eu.log;

import java.util.HashMap;

/**
 * 存储设备类厂
 * @author 吴振振
 * @version 1.0 alpha
 */
class StorageFactory {
	private static HashMap<String,Storage> storageMap=new HashMap<String, Storage>();
	
	static{
		Storage storage=buildStorage("storage");
		if(storage!=null)
			storageMap.put("DEFAULT", storage);
		else
			LogFactory.setError("can't initialize default storage");
		for(Rank rank:Rank.values()){
			storage=buildStorage("storage."+rank);
			if(storage!=null)
				storageMap.put(rank.toString(), storage);
		}
	}
	
	protected static Storage getDefaultStorage() {
		return storageMap.get("DEFAULT");
	}

	protected static Storage getStorage(Rank rank) {
		return storageMap.get(rank.toString());
	}
	
	private static Storage buildStorage(String key){
		String uri=ConfigGetter.getParameter(key);
		if(uri==null)
			return null;
		if(uri.startsWith("local:"))
			return eu.log.db.StorageFactory.newStorage(uri.replace("local:", ""));
		return null;
	}
}
